define(function(require, exports, module) {

	"use strict";
	require("mui");
	require("jquery");
	require("common");

	var abpdata = require("abpinit");
	var abp = abpdata.abpstart;
	var template = require("template");
	require('http://g.alicdn.com/ilw/ding/0.8.9/scripts/dingtalk.js');
	//钉钉返回清除缓存
	var dingTalkNav = require('dd_config');
	//ios
	dingTalkNav.LeftNavBar();
	//ad
	dingTalkNav.leftAndroid();
	dingTalkNav.RightNavBar(false, "更多", "default");
	var page = require("pageui");
	var getFunList = require("../getFunList/getFunList.js");
	getFunList.SortList("SortList", "#sortListShow");

	var chioceTab = require("chioceTab");
	var isBom = abp.request.queryString("isBom");
	if(isBom && isBom == "true")
		isBom = true;
	else
		isBom = false;

	var catalogId = 0;
	var orderBy = "";

	var dataModel = {
		"keyword": "",
		"catalogId": catalogId,
		"orderBy": orderBy,
		"whId": 0,
		"isBom": isBom
	};

	var loadEnd = function() {};

	page.init({
		id: "goodsList",
		tempid: "productlist",
		isCache: true,
		noneMsg: "还没有可模拟的物料清单哦，快去PC端后台添加吧！",
		"loadEnd": loadEnd
	}, {
		swipeBack: true
	}, abp.services.app.infoGoods.getPage, dataModel).dataLoad(dataModel, 'init');

	mui("body").on("tap", "#sortListShow li", function() {
		catalogId = $(this).find("a").attr("data-id");
		dataModel.catalogId = catalogId;
		page.dataLoad(dataModel);
	});
	mui("body").on("tap", "#orderByDate li", function() {
		orderBy = "DataModified " + $(this).attr("data-orderby");
		dataModel.orderBy = orderBy;
		page.dataLoad(dataModel);
	});

	mui("body").on("tap", ".pop-tab-conitem li", function() {
		chioceTab.muiSure();
	});

	mui("body").on("tap", ".product-check li", function() {

		var checkObj = $(this).find("input[type='checkbox']").eq(0);
		if(!checkObj.attr("checked")) {
			checkObj.attr("checked", "checked");
		} else {
			checkObj.removeAttr("checked", "checked");
		}

		var hasOn = $(document).find("input[type='checkbox']:checked");

		if(hasOn.length > 0) {
			$("#finishCheck").show();
		} else {
			$("#finishCheck").hide();
		}

		return false;

	});

	//复选框
	mui("body").on("tap", "#finishCheck", function() {
		var hasOn = $(document).find("input[type='checkbox']:checked");
		var hasOnID = [];
		var checkedGoods = [];

		$.each(hasOn, function() {
			hasOnID.push($(this).attr("data-id"));
		});

		for(var k = 0; k < hasOnID.length; k++) {
			checkedGoods.push(page.dataCache[hasOnID[k]]);
		}

		checkedGoods = JSON.stringify(checkedGoods);
		sessionStorage.checkedGoods = checkedGoods;

	});

});